package de.lang.rollo.controller.model;

import javax.persistence.Id;

import org.mongojack.DBRef;
import org.mongojack.ObjectId;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.pi4j.io.gpio.Pin;

import de.lang.rollo.controller.enums.SchalterType;
import de.lang.rollo.controller.model.json.PinDeserializer;
import de.lang.rollo.controller.model.json.PinSerializer;

public class Schalter {

	@Id
	private String id;

	@JsonSerialize(using = PinSerializer.class)
	@JsonDeserialize(using = PinDeserializer.class)
	public Pin pin;

	public SchalterType type;

	public String name;
	// public RolloMotor motor;
//	@ObjectId
//	public DBRef<RolloMotor, String> motor;
	@JsonIgnore
	public RolloMotor motor = null;
	
	public String motor_id = null;

	@JsonIgnore
	public int pressCounter = 0;

	public void incrementCounter() {
		pressCounter++;
	}

	public void resetCounter() {
		pressCounter = 0;
	}

	@ObjectId
//	@JsonProperty("_id")
	public String getId() {
		return id;
	}

	@ObjectId
//	@JsonProperty("_id")
	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Pin getPin() {
		return pin;
	}

	public void setPin(Pin pin) {
		this.pin = pin;
	}

	 public RolloMotor getMotor() {
	 return motor;
	 }
	
	 public void setMotor(RolloMotor motor) {
	 this.motor = motor;
	 this.motor_id = motor.getId();
	 }
	 
	 
	
	

//	public RolloMotor getMotor() {
//		return motor.fetch();
//	}
//
//	public void setMotor(RolloMotor motor) {
//		this.motor = new DBRef<RolloMotor, String>(motor.id, RolloMotor.class);
//	}
	
	

	public String getMotor_id() {
		return motor_id;
	}

	public void setMotor_id(String motor_id) {
		this.motor_id = motor_id;
	}

	public SchalterType getType() {
		return type;
	}

//	public DBRef<RolloMotor, String> getMotor() {
//		return motor;
//	}
//
//	public void setMotor(DBRef<RolloMotor, String> motor) {
//		this.motor = motor;
//	}

	public void setType(SchalterType type) {
		this.type = type;
	}

}
